{% extends 'base.html' %}

{% block title %}添加碳排放因子{% endblock %}

{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
    <h1>添加碳排放因子</h1>
    <a href="{{ url_for('factor.factor_list') }}" class="btn btn-outline-secondary">返回列表</a>
</div>

<div class="card">
    <div class="card-body">
        <form method="post" action="{{ url_for('factor.add_factor') }}">
            <div class="row mb-3">
                <div class="col-md-6">
                    <label for="name" class="form-label">因子名称 <span class="text-danger">*</span></label>
                    <input type="text" class="form-control" id="name" name="name" required>
                </div>
                <div class="col-md-6">
                    <label for="gas_type" class="form-label">气体种类 <span class="text-danger">*</span></label>
                    <input type="text" class="form-control" id="gas_type" name="gas_type" required>
                </div>
            </div>

            <div class="row mb-3">
                <div class="col-md-6">
                    <label for="value_type" class="form-label">值类型 <span class="text-danger">*</span></label>
                    <select class="form-select" id="value_type" name="value_type" required>
                        <option value="直接排放">直接排放</option>
                        <option value="间接排放">间接排放</option>
                    </select>
                </div>
                <div class="col-md-6">
                    <label for="emission_value" class="form-label">碳排值 <span class="text-danger">*</span></label>
                    <input type="number" step="any" class="form-control" id="emission_value" name="emission_value" required>
                </div>
            </div>

            <div class="row mb-3">
                <div class="col-md-6">
                    <label for="factor_type" class="form-label">因子类型 <span class="text-danger">*</span></label>
                    <select class="form-select" id="factor_type" name="factor_type" required>
                        <option value="标准因子">标准因子</option>
                        <option value="自建因子">自建因子</option>
                    </select>
                </div>
                <div class="col-md-6">
                    <label for="category_id" class="form-label">分类 <span class="text-danger">*</span></label>
                    <select class="form-select" id="category_id" name="category_id" required>
                        <option value="">-- 选择分类 --</option>
                        {% for category in categories %}
                        <option value="{{ category.id }}">{{ '└─ ' * (category.level - 1) }}{{ category.name }}</option>
                        {% endfor %}
                    </select>
                </div>
            </div>

            <div class="mb-3">
                <label for="source" class="form-label">来源</label>
                <input type="text" class="form-control" id="source" name="source">
            </div>

            <div class="mb-3">
                <label for="formula_description" class="form-label">碳排因子公式说明</label>
                <textarea class="form-control" id="formula_description" name="formula_description" rows="3"></textarea>
            </div>

            <div class="d-grid gap-2 d-md-flex justify-content-md-end">
                <button type="submit" class="btn btn-primary">保存</button>
                <a href="{{ url_for('factor.factor_list') }}" class="btn btn-outline-secondary">取消</a>
            </div>
        </form>
    </div>
</div>
{% endblock %}
<div class="col-md-6">
    <label for="category_id" class="form-label">分类 <span class="text-danger">*</span></label>
    <select class="form-select" id="category_id" name="category_id" required>
        <option value="">-- 选择分类 --</option>
        {% for category in categories %}
        <option value="{{ category.id }}">{{ '└─ ' * (category.level - 1) }}{{ category.name }}</option>
        {% endfor %}
    </select>
</div>